package com.java.tutorials.jdk7.database;

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.ResultSet;
/**
 * Created by xuzhike on 2016/1/23.
 */
public class PseudoColumnsTest {
    public static void main(String[] args) throws Exception {
        Connection con = DriverManager.getConnection(
                "jdbc:mysql://localhost:3306/pssm", "root", "");
        DatabaseMetaData metaData = con.getMetaData();
        ResultSet rs = metaData.getCatalogs();
        while (rs.next()) {
            System.out.println(rs.getString("TABLE_CAT"));
        }

        //4，获取表名列表
        ResultSet rs1 = metaData.getTables(con.getCatalog(), null, null, new String[]{"comp_audit_log"});
        while (rs1.next()) {
            System.out.println(rs.getString("COLUMN_NAME"));
        }
        ResultSet resultSet = metaData.getPseudoColumns("", "",
                "comp_audit_log", "");

        while (resultSet.next()) {
            System.out.println(resultSet.getString("TABLE_SCHEM ") + " - "
                    + resultSet.getString("COLUMN_NAME "));
        }

    }
}
